<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/include/header.jsp"%>
<!-- 加载树-->
<%@ include file="/include/zTree.jsp"%>
<script type="text/javascript">
	$(document).ready(function () {
		loadTree();
	});
	var defaultSetting = {
		data : {
			simpleData : {
				enable : true
			}
		}, view : {
			selectedMulti : false
		}

	};
	function loadTree() {
		$.post("${ctx}/sysAuthority/mgr?ts=" + new Date().getTime(), function (data) {
			$("#authorityTree").html("");
			$.fn.zTree.init($("#authorityTree"), defaultSetting, data);

			//全部节点都要展开
			var treeObj = $.fn.zTree.getZTreeObj("authorityTree");
			//treeObj.expandAll(true);
		});
	}
	
	function search() {
		loadTree();
	}
</script>
</head>
<body>
	<div class="main_panel">
		<div class="ch_panel" id="queryDiv" style="height: 100%; overflow: auto;">
			<div class="r_action">
				<!-- <input type="button" class="save_btn" value="新增业务系统" id="addServiceSystem"/> -->
				<input type="button" class="save_btn" value="新增" id="addBtn" />
				<input type="button" class="save_btn" value="修改" id="editBtn" />
				<input type="button" class="save_btn" value="删除" id="deleteBtn" />
				<input type="button" class="save_btn" value="查看" id="viewBtn" />

			</div>
			<div id="authorityTree" class="ztree" style="background-color: white;" />
		</div>
	</div>
	<script type="text/javascript">
		// 获取选中节点的ID
		function getSelectedNodeId () {
			var treeObj = $.fn.zTree.getZTreeObj("authorityTree");
			var nodes = treeObj.getSelectedNodes();
			if (nodes.length != 1) {
				alert("请选择一个节点！");
				return false;
			}
			return nodes[0].id;
		}

		var allAuthority = "";
		$(function () {
			// 添加
			$("#addBtn").click(function() {
				var parentId = getSelectedNodeId();
				if (parentId == "") {
					return;
				}
				parent.member_add("新增子权限", "${ctx}/sysAuthority/toAdd?parentId=" + parentId,800,460);
			});
			
			// 编辑
			$("#editBtn").click(function () {
				var authorityId = getSelectedNodeId();
				if (authorityId == "") {
					return;
				}
				parent.member_add("编辑权限信息", "${ctx}/sysAuthority/toEdit?authorityId="+authorityId,800,460);
				
			});
			
			// 详细
			$("#viewBtn").click(function () {
				var authorityId = getSelectedNodeId();
				if (authorityId == "") {
					return;
				}
				parent.member_add("查看权限信息", "${ctx}/sysAuthority/view?authorityId="+authorityId,600,300);
				
			});
			
			// 4、删除
			$("#deleteBtn").click(function () {
				var authorityId = getSelectedNodeId();
				if (authorityId == "") {
					return;
				}
				if (confirm('确定删除？')) {
					$.post("${ctx}/sysAuthority/delete", {
						authorityId : authorityId, csrfToken : "${csrfToken}"
					}, function (result) {
						if ("succ" == result) {
							alert("操作成功");
							// 刷新列表页面
							self.location.replace("${ctx}/sysAuthority/list"); //如果操作成功则跳到列表界面
						} else {
							alert(result);
						}
					}, "json");
				}

			});

			/* $("#addServiceSystem").click(function(){
				seajs.use("component/dialog", function (dialog) {
				    sysAuthorityDialog = new dialog({
				        "width" : 800,
				        "height" : 530,
				        "contentType" : "iframe",
						"html" : "${ctx}/sysAuthority/toAddServiceSystem", // 内容
				        "title" : "添加系统授权信息" //标题
					});
				});
			}); */

		});
	</script>

</body>
</html>